package logic.ui.uieditscene
{
	import common.core.GMouse;
	import common.core.GSprite;
	import common.manager.GUI;
	import common.manager.ObserverEvt;
	
	import component.ComponentLib;
	import component.show.containers.tree.Tree;
	import component.show.containers.tree.TreeEvent;
	
	import fl.controls.Button;
	import fl.controls.Label;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.security.ReferencesValidationSetting;
	import flash.utils.getDefinitionByName;
	
	import logic.def.Assets;
	import logic.ui.cell.ScanComponent_LstCell;
	
	import xml.item.ItemNode;

	public class ScanComponentMed extends GSprite
	{
		public static const NAME : String = "ScanComponentMed";
		
		public static const SCANCOMPONENT_CLICKCOMPONENTLSTCELL:String = "SCANCOMPONENT_CLICKCOMPONENTLSTCELL";
		
		public var  m_dpComponentLst : XML ;
		
		private var m_componentLst : Tree; 
		
		public function ScanComponentMed() 
		{
			m_componentLst = new Tree;
			
			GUI.add(NAME,this,false);
			GUI.setAlgin(NAME,GUI.ALIGN_LEFT,GUI.ALIGN_TOP);
			GUI.setOffest(NAME,0,15);
			
			m_dpComponentLst = 	<node label="root">    
									<node label="Button"/>  
									<node label="List"/>   
									<node label="DataGrid"/>
									<node label="Label" />
									<node label="TextInput" />
									<node label="TextArea" />
									<node label="UILoader" />
									<node label="ComboBox" />
									<node label="CheckBox" />
									<node label="UIFrame" />
									<node label="Image" />
									<node label="SimpleBtn" />
									<node label="Tree" />
									<node label="ScrollPane"/>
									<node label="ToggleButton"/>
								</node>;
			
			m_componentLst.treeWidth = 100;
			m_componentLst.itemRenderer = ScanComponent_LstCell;
			m_componentLst.dataProvider = m_dpComponentLst;
			
			this.addChild(m_componentLst);
			
			this.addEventListener(TreeEvent.CLICK_NODE,OnClickComponentCell);
		}
		
		public override function destory() : void
		{
			this.removeEventListener(TreeEvent.CLICK_NODE,OnClickComponentCell);
			
			m_dpComponentLst = null;
			m_componentLst = null;
		}
		
		private function OnClickComponentCell(evt : TreeEvent) : void
		{
			var cellData : Object = evt.item.data;
			
			var viewSprite : GSprite = new GSprite;
//				new ComponentLib.lib[cellData["label"]] as Sprite;
			
			var lab : Label = new Label;
			lab.text = cellData["label"];
			
			lab.x = 15;
			
			viewSprite.addChild(lab);
			
			viewSprite.opaqueBackground = 0xCD950C;
			
			GMouse.setHandOffest(new Point(1,1));
			GMouse.showHand(viewSprite,cellData);
			
			ObserverEvt.Send(SCANCOMPONENT_CLICKCOMPONENTLSTCELL);
		}
	}
}